package com.youbug.system.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.youbug.common.vo.QueryVo;
import com.youbug.system.entity.Job;
import com.youbug.system.service.IJobService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.*;
import com.youbug.common.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 定时任务 前端控制器
 * </p>
 *
 * @author youbug
 * @since 2023-11-12
 */
@RestController
@RequestMapping("/job")
public class JobController {
@Autowired
private IJobService jobService;

    @PostMapping("/getJobPage")
    public R<IPage<Job>> getJobPage(@RequestBody QueryVo<Job> queryVo){

        IPage<Job> jobs = jobService.getJobPage(queryVo);

        return R.ok(jobs);
    }

    @GetMapping("/getJobById/{id}")
    public R<Job> getMenusForRole(@PathVariable Integer id){

        Job job = jobService.getById(id);

        return R.ok(job);
    }

    @PostMapping("/add")
    public R<Boolean> add(@RequestBody Job job){

        boolean save = jobService.save(job);

        return  R.ok(save);
    }

    @PostMapping("/update")
    public R<Boolean> update(@RequestBody Job job){

        boolean update = jobService.updateById(job);

        return  R.ok(update);
    }

    @GetMapping("/delete/{id}")
    public R<Boolean> delete(@PathVariable Integer id){

        boolean remove = jobService.removeById(id);

        return  R.ok(remove);
    }

    @GetMapping("/exec/{jobCode}")
    public R<Boolean> exec(@PathVariable String jobCode){

        boolean exec = jobService.exec(jobCode);

        return  R.ok(exec);
    }
}

